package com.dao.impl;

import com.bean.History;
import com.bean.HistoryList;
import com.dao.BaseDao;
import com.dao.HistoryDao;

import java.util.List;

public class HistoryDaoImpl extends BaseDao implements HistoryDao {
    //删除全部
    @Override
    public int deleAll() {
        String sql = "DELETE FROM `history`";
        return update(sql);
    }

    //删除历史
    @Override
    public int deleHis(Integer id) {
        String sql = "DELETE FROM `history`WHERE `id`=?";
        return update(sql, id);
    }

    //添加历史记录
    @Override
    public int addHistory(History history) {
        String sql = "insert into `history`(`id`,`userId`,`videoId`,`startTime`,`watchTime`)values(?,?,?,?,?)";
        return update(sql, history.getId(), history.getUserId(), history.getViedoId(), history.getStartTime(), history.getWatchTime());
    }


    //历史记录查询
    @Override
    public List<HistoryList> queryHistory(Integer id) {
        String sql = "SELECT viedo.vname,viedo.pic,viedo.path,`user`.userName,history.id , history.startTime FROM viedo LEFT JOIN history ON viedo.id=history.videoId LEFT JOIN `user` on history.userId=`user`.id  WHERE  `user`.id=?";
        return queryForList(HistoryList.class, sql, id);
    }


}
